import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    isLogin: false,
    userId: '',
    username: '',
    userImg: '',
    
    queryKeyword: '',
    // 默认为全部分类
    sortId: '',
    // 默认为商品帖
    goodsWant: 'g',

    // 进入商品详情页面，表明该商品是商品帖还是求购帖
    goodsWantDetail: '',

    // 商品ID
    goodsId: '',

    // 用户个人主页分类
    profileIndex: ''
  },
  mutations: {
    changeLogin(state) {
      state.isLogin = !state.isLogin
    },
    changeUserId(state, payload) {
      state.userId = payload
    },
    changeUserName(state, payload) {
      state.username = payload
    },
    changeUserImg(state, payload) {
      state.userImg = payload
    },

    changeQueryKeyword(state, payload) {
      state.queryKeyword = payload
    },
    changeSortId(state, payload) {
      state.sortId = payload
    },
    changeGoodsWant(state, payload) {
      state.goodsWant = payload
    },

    changeGoodsWantDetail(state, payload) {
      state.goodsWantDetail = payload
    },

    changeGoodsId(state, payload) {
      state.goodsId = payload
    },

    changeProfileIndex(state, payload) {
      state.profileIndex = payload
    }
  }
})

export default store